home *** CD-ROM | disk | FTP | other *** search
- /* gennums.c generate number tables for stringart */
-
- #include <stdio.h> /* standard I/O */
- #include <fixmath.h> /* floating point math */
- #include <math.h> //• Added by KAL.
- /*
- This demo creates random vector designs. This is accomplished by
- randomly choosing a function for each coordinate halve of the two
- points describing a vector that moves through two dimensional
- space. Both x coordinate halves cannot be the same since the design
- would simply be a collection of vertical lines. Similarly both
- y coordinate halves cannot be the same.
-
- The functions are:
-
- function[0][x] = sin( 2 * PI * x / numLines )
- function[1][x] = -sin( 2 * PI * x / numLines )
- function[2][x] = cos( 2 * PI * x / numLines )
- function[3][x] = -cos( 2 * PI * x / numLines )
- function[4][x] = sin( 4 * PI * x / numLines )
- function[5][x] = -sin( 4 * PI * x / numLines )
- function[6][x] = cos( 4 * PI * x / numLines )
- function[7][x] = -cos( 4 * PI * x / numLines )
- function[8][x] = sin( 6 * PI * x / numLines )
- function[9][x] = -sin( 6 * PI * x / numLines )
- function[10][x] = cos( 6 * PI * x / numLines )
- function[11][x] = -cos( 6 * PI * x / numLines )
- function[12][x] = 2 * abs( x - (numLines / 2) - 1 )
-
- The values of the functions were pre computed to have the demo
- run as fast as possible. The program will only terminate on
- interrupt since it is in an endless loop.
- */
-
- /* these should be in a common header file, but I'm lazy */
- #define numLines 343 /* number of vectors in a design */
- #define num_functions 12 /* number of functions */
-
- int p [numLines];
-
- main()
- {
- int i, j, k, l, m;
- FILE *f;
-
- f = fopen ("NewStringNums.c", "w");
- fprintf (f, "\n\t/* This source file generated by gennums.c */\n\n\n");
- fprintf (f, "#define num_functions %d\n", num_functions);
- fprintf (f, "#define numLines %d\n\n", numLines);
- fprintf (f, "int p [num_functions][numLines] = {\n\n");
- for (i = 0; i < num_functions; i++)
- {
- cypher (i, 1024);
-
- /* scaling down is faster with a power of 2 */
- DumpArray (f, i);
- }
- fprintf (f, "\t}\n};\n\n");
- fclose (f);
- }
-
- DumpArray (f, n) FILE *f; int n;
- {
- int i;
-
- if (n != 0)
- fprintf (f, "\t},\n\n");
- fprintf (f, "\t{\n");
-
- for (i = 0; i < numLines; i++)
- {
- fprintf (f, "\t%d", p[i]);
- if (i != numLines - 1)
- fprintf (f, ",");
- if (i % 7 == 6)
- fprintf (f, "\n");
- }
- }
-
-
- #define PI 3.1415927
-
- /* Hey Uncle Jed... */
- int cypher (int func, int scale)
- {
- float tmp;
- int x;
-
- for (x = 0; x < numLines; x++)
- {
- /* clumsy, but doesn't need to be efficient */
- switch (func)
- {
- case 0:
- tmp = sin( 2 * PI * x / numLines);
- break;
-
- case 1:
- tmp = -sin( 2 * PI * x / numLines);
- break;
-
- case 2:
- tmp = cos( 2 * PI * x / numLines);
- break;
-
- case 3:
- tmp = -cos( 2 * PI * x / numLines);
- break;
-
- case 4:
- tmp = sin( 4 * PI * x / numLines);
- break;
-
- case 5:
- tmp = -sin( 4 * PI * x / numLines);
- break;
-
- case 6:
- tmp = cos( 4 * PI * x / numLines);
- break;
-
- case 7:
- tmp = -cos( 4 * PI * x / numLines);
- break;
-
- case 8:
- tmp = sin( 6 * PI * x / numLines);
- break;
-
- case 9:
- tmp = -sin( 6 * PI * x / numLines);
- break;
-
- case 10:
- tmp = cos( 6 * PI * x / numLines);
- break;
-
- case 11:
- tmp = -cos( 6 * PI * x / numLines);
- break;
-
- case 12:
- tmp = 2 * abs( x - (numLines / 2) - 1); /* not used */
- break;
-
- default:
- tmp = x; /* shouldn't happen */
- break;
- }
- p [x] = (int)(tmp * scale);
- }
- }
-
-
-
-
-